{% extends '__base__.html' %}

{% block title %}学生{% endblock %}

{% block beforehead %}

<script>

function initVM(data) {
    var vm = new Vue({
        el: '#vm',
        data: {
            students: data.items,
            page: data.page
        },
        methods: {
            edit_student: function (student) {
                location.assign('/manage/students/edit?id=' + student.id);
            },
            delete_student: function (student) {
                if (confirm('确认要删除“' + student.name + '”？删除后不可恢复！')) {
                    postJSON('/api/students/' + student.id + '/delete', function (err, r) {
                        if (err) {
                            return alert(err.message || err.error || err);
                        }
                        refresh();
                    });
                }
            }
        }
    });
    $('#vm').show();
}

$(function() {
    getJSON('/api/students', {
        page: {{ page_index }}
    }, function (err, results) {
        if (err) {
            return fatal(err);
        }
        $('#loading').hide();
        initVM(results);
    });
});

</script>

{% endblock %}

{% block content %}

<div class="uk-width-1-1 uk-margin-bottom">
    <div class="uk-panel uk-panel-box">
        <ul class="uk-breadcrumb">
            <li><a href="/manage/comments">评论</a></li>
            <li><a href="/manage/blogs">日志</a></li>
            <li><a href="/manage/users">用户</a></li>
            <li class="uk-active"><span>学生</span></li>
        </ul>
    </div>
</div>

<div id="error" class="uk-width-1-1">
</div>

<div id="loading" class="uk-width-1-1 uk-text-center">
    <span><i class="uk-icon-spinner uk-icon-medium uk-icon-spin"></i> 正在加载...</span>
</div>

<div id="vm" class="uk-width-1-1">
    <a href="/manage/students/create" class="uk-button uk-button-primary"><i class="uk-icon-plus"></i>新学生</a>

    <table class="uk-table uk-table-hover">
        <thead>
            <tr>
                <th class="uk-width-5-10">学号</th>
                <th class="uk-width-2-10">姓名</th>
                <th class="uk-width-2-10">生日</th>
                <th class="uk-width-1-10">操作</th>
            </tr>
        </thead>
        <tbody>
            <tr v-repeat="student: students">
                <td>
                    <span v-text="student.student_no"></span>
                </td>
                <td>
                    <span v-text="student.student_name"></span>
                </td>
                <td>
                    <span v-text="student.birth"></span>
                </td>
                <td>
                    <a href="#0" v-on="click: edit_student(student)">
                        <i class="uk-icon-edit"></i>
                        <a href="#0" v-on="click: delete_student(student)"><i class="uk-icon-trash-o"></i>
                </td>
            </tr>
        </tbody>
    </table>

    <div v-component="pagination" v-with="page"></div>
</div>

{% endblock %}
